package com.anlu.zk.simple;

import com.anlu.zk.core.ZooKeeperDistributedLock;
import com.anlu.zk.util.ZookeeperLock;
import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.recipes.locks.InterProcessLock;
import org.apache.curator.framework.recipes.locks.InterProcessMutex;
import org.apache.curator.retry.ExponentialBackoffRetry;

import java.text.SimpleDateFormat;
import java.util.Date;

public class OrderNumGenerater {


    private static int num=0;
    private static Object lock = new Object();


    public String getNumber(){
        synchronized (lock){
            num=num+1;
            return "当前订单号："+num;
        }
    }




//    public String getNumber(){
//        try{
//            zooKeeperDistributedLock.acquireDistributedLock();
//            num=num+1;
//            return "当前订单号："+num;
//        }finally {
//            zooKeeperDistributedLock.unlock();
//        }
//
//
//    }





//    public String getNumber(){
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
//        String result = simpleDateFormat.format(new Date())+"-"+ ++num;
//        return result;
//    }
}
